<template>
    <div class="NewUnit" @click="noneDialogVisible">
        <div @click.stop>
            <div class="title">
                添加单元
            </div>
            <div class="from">
                <div>
                    <span>单元名称</span>
                    <input v-model="courseName" type="text" placeholder="新建单元名称, 必填">
                </div>
            </div>
            <div @click="newCourse" class="button" :class="[courseName?'button-1':'']">创建</div>
        </div>
    </div>
</template>

<script setup>
import { ref } from "vue";
import workApi from "@/http/work/workApi";
import { useAllStore } from "@/stores/all";
const all = useAllStore()
// 取消模态框
const props = defineProps(['setIsNewUnit',"setData"]) // 获取传入方法
function noneDialogVisible(){
    props.setIsNewUnit()
}

// 发送创建单元
let courseName = ref("")
const newCourse=()=>{
    workApi.post("teacher/subject_unit",{
        subject_name:all.courseContainerInfo.name,
        unitName:courseName.value
    }).then((res)=>{
        courseName = ref("")
        props.setData(res.data[0].unit)
        props.setIsNewUnit()
    })
}
</script>

<style scoped lang="less">
.NewUnit {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    color: black;
    background-color: rgba(0, 0, 0, .6);
    backdrop-filter: blur(2px);
    z-index: 1;

    > div {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 25%;
        min-width: 300px;
        height: 384px;
        border-radius: 20px;
        background-color: white;

        .title {
            height: 40px;
            margin-bottom: 40px;
            text-align: center;
            line-height: 40px;
            font-size: 20px;
            font-weight: 600;
            border-bottom: 1px solid black;
        }

        .from {
            > div {
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                margin: 20px 0;
                span{

                }
                input {
                    width: 80%;
                    border-radius: 15px;
                    background-color: rgba(0, 0, 0, .1);
                }
            }

        }
        .button{
            width: 80%;
            height: 50px;
            margin: 50px auto;
            text-align: center;
            line-height: 50px;
            border-radius: 25px;
            background-color: rgba(0, 0, 0, .1);
        }
        .button-1{
            background-color: #4f95f5;
        }
    }
}
</style>